<template>
    <h2>房间号列表</h2>
    房号<input type="text" v-model="prist.name">
    创建时间<input type="date" v-model="prist.sdate">
    <input type="button" value="查询" @click="showlist">
<br>
<input type="button" value="排房列表" @click="owjnadww">
    <div>
        <input type="button" value="导出" @click="daochuexacl">
        <input type="file" @change="changeunk"><input type="button" value="导入" @click="pwoksniw">
    </div>
    <table>
        <tr>
            <td>房号</td>
            <td>房间类型</td>
            <td>创建时间</td>
            <td>图片</td>
            <td>房态</td>
            <td>状态</td>
            <td>操作</td>
        </tr>
        <tr v-for="item in list">
            <td>{{item.nname}}</td>
            <td>{{item.rname}}</td>
            <td>{{item.cdate.substr(0,10)}}</td>
            <td><img :src="'https://localhost:7214'+item.picture" width="60" height="60"></td>
            <td>{{ item.statename }}</td>
            <td>{{item.nstates==1?"启用":"停用"}}</td>
            <td><input v-if="item.nstates==1" type="button" value="下架" @click="xiajiaokwm(item.nid,item.nstates)"><input v-if="item.nstates==0" type="button" value="上架" @click="xiajiaokwm(item.nid,item.nstates)"><input type="button" value="修改" @click="upkwnok(item.nid)"><input type="button" value="排房" @click="paifinjni(item.nid)"></td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {onMounted, reactive, toRefs} from 'vue'
  import {useRouter,useRoute} from 'vue-router'
  import axios from 'axios'
  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    prist:{
        name:'',
        sdate:''
    },
    list:[],
    a:''
  })
  let {prist,list,a} =toRefs(data)

  onMounted(()=>{
    showlist()
  })

  const showlist=()=>{
    let obj={
        namen:prist.value.name,
        kdate:prist.value.sdate
    }
    axios({
        url:'/api/Room/GetTypenums',
        method:'get',
        params:obj
    })
    .then(res=>{
        list.value=res.data.data;
    })
  }
//修改
  const upkwnok=(nid:any)=>{
    router.push({
        path:'/updnum',
        query:{nid}
    })
  }
//修改状态
  const xiajiaokwm=(nid:any,nstates:any)=>{
        if(nstates==1){
            nstates=0;
        }else{
            nstates=1;
        }
        let obj={
          nid:nid,
          states:nstates
        }
        axios({
          url:'/api/Room/Updstates',
          method:'get',
          params:obj
        })
        .then(res=>{
            if(res.data.data==1){
                alert("成功")
                showlist()
            }else{
                alert("失败")
            }
        })  
  }
//导出文件
  const daochuexacl=()=>{
    location.href='https://localhost:7214'+'/api/Room/Exportexcal'
  }

  const changeunk=(e:any)=>{
    a.value=e.target.files[0]
  }

  const paifinjni=(nid:any)=>{
    if(confirm("确定排此房间吗？")){
      let obj={
        "numid": nid,
  "isdel": false
      }
      axios({
        url:'/api/Room/Addrow',
        method:'post',
        data:obj
      })
      .then(res=>{
        if(res.data.data==1){
          alert("排房成功")
          showlist()
        }else{
          alert("排房失败，请重新选择房间")
        }
      })
    }
  }

  const owjnadww=()=>{
    router.push('showorder')
  }
  </script>
  
  <style scoped>
  
  </style>